package com.xncoding.tomcat.socket02;

import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class MyTomcat {

    private static final int PORT = 8090;
    public void start() throws IOException {
        System.out.println("my tomcat starting...");
        ServerSocket socket = new ServerSocket(PORT);
        while (true) {
            Socket accept = socket.accept();
            OutputStream outputStream = accept.getOutputStream();
            // 分别封装 Request 和 Response
            Request request = new Request(accept.getInputStream());
            Response response = new Response(outputStream);
            // 根据 request 中的 url，输出
            response.outputHtml(request.getUrl());
            accept.close();
        }
    }

    public static void main(String[] args) throws IOException {
        MyTomcat tomcat = new MyTomcat();
        tomcat.start();
    }
}
